package com.lf.web.controller.system;

import com.lf.web.service.ServiceSupport;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.util.ServletContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;

public class ConfigController extends ActionSupport implements ServletContextAware{

	private WebApplicationContext wac;
	private ServiceSupport cs;

	private String act = "";

	public void setAct(String act) {
		this.act = act;
	}
	
	public void setServletContext(ServletContext servletContext) {
		wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
	}

	public String execute() {
		String rsstr = "";
		switch (act) {
		case "add":
			cs = (ServiceSupport) wac.getBean("CconfigAddService");
			break;
		case "update":
			cs = (ServiceSupport) wac.getBean("CconfigUpdateService");
			break;
		case "remove":
			cs = (ServiceSupport) wac.getBean("CconfigRemoveService");
			break;
		case "detail":
			cs = (ServiceSupport) wac.getBean("CconfigDetailService");
			break;
		default:
			cs = (ServiceSupport) wac.getBean("CconfigService");
		}
		rsstr = cs.execute();
		return rsstr;
	}
}
